<template>
  <div>
    <Spin :spinning="loading" tip="Loading...">
      <!-- 车型新增维护 -->
      <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="4" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"></TopFilter>
      <Spin :spinning="loading" tip="导入中，请稍后...">
        <FilterTable
          ref="table"
          height="auto"
          :columns="columns"
          :params="fetchParams"
          :fetchapi="fetchapi"
          :datakey="'records'"
          :onColumnsChange="(columns) => (this.columns = columns)"
          :onRowSelectChange="selectChange"
        >
        </FilterTable>
      </Spin>
      <div
        :style="{
          position: 'absolute',
          left: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <multiuse-button type="primary" @click="saveDialog">保 存</multiuse-button>
        <multiuse-button @click="closeDialog">关 闭</multiuse-button>
      </div>
    </Spin>
  </div>
</template>
<script>
import { getAppId} from '@/assets/js/auth';
import {dictionary} from'@/utils/dictMixin';
import { getCarModelArray,addModel } from '@/api/graphic/carModelSettings/index.js';
export default {
  mixins: [dictionary],
  data() {
    return {
      loading: false,
      dataList1: [],
      visible: false,
      collapse:false,
      selectedRows: [], //选中系统
      fetchapi: getCarModelArray,
      saveData: null,
      columns: this.creatHeader(),
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中车型
      disableds: true,
      topFilterInit: this.topFilterInitFun(),
    };
  },
  created() {
  },
  methods: {
    //保存
    saveDialog() {
      if (this.saveData !== null) {
        this.loading = true;
        // console.log(this.saveData)
        addModel(this.saveData).then((res)=>{
          if (res.resultCode === 200) {
              // console.log(res)
              this.loading = false;
              this.$emit('save');
              return this.$notify.success({title: '提示信息', message: '保存成功'});
            } else {
              this.loading = false;
              this.$notify.error({title: '提示信息', message: res.errMsg || '保存失败!'});
            }
        });
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close', {visible: false, data: this.selectedRows, type: 'close'});
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          fixed: 'left',
          sorter: true,
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        // 车型代码、车型名称、创建人、创建时间、修改人、修改时间
        { title: '车型代码', dataIndex: 'modelCode', sorter: true },
        { title: '车型名称', dataIndex: 'modelName', sorter: true },
      ];
    },
    selectChange(rows) {
      this.saveData = rows;
      this.disableds = this.selectedRows.length <= 0;
      // console.log(this.selectedRows);
    },
    //搜索数据
    topFilterInitFun() {
      // 车型代码、车型名称
      return [
        {
          type: 'INPUT',
          label: '车型代码',
          fieldName: 'modelCode',
          placeholder: '请输入',
          initialValue: '',
          rules: [{ max: 20, message: '长度不能大于20个字符', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '车型名称',
          fieldName: 'modelName',
          placeholder: '请输入.',
          initialValue: '',
          rules: [{ max: 20, message: '长度不能大于20个字符', trigger: 'blur' }]
        },
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
      // console.log(val);
    },
  }
};
</script>

<style lang="less" scoped></style>
